package com.wzh.loveEmail.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.StrUtil;
import com.wzh.loveEmail.config.LoveConfig;
import com.wzh.loveEmail.service.Impl.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试邮件发送
 *
 * @author qzz
 */
@RestController
@RequestMapping("/mail")
public class SendMailController {

    @Autowired
    private MailService mailService;


    @Autowired
    private LoveConfig loveConfig;

    /**
     * 发送HTML邮件
     *
     * @param to
     * @param subject
     * @param content
     */
    @GetMapping("/sendHtmlMailMessage")
    public void sendHtmlMailMessage(String to, String subject, String content) {
        mailService.sendHtmlMailMessage(to, subject, content);
    }


    /**
     * 发送每日推送
     */
    @GetMapping("/send")
    public void send() {
        DateTime now = new DateTime();
        mailService.sendHtmlMailMessage(String.join(",", loveConfig.getSendTo()),
                StrUtil.format("{}月{}日 早安推送", now.month(), now.dayOfMonth()),
                mailService.getHtml()
        );
    }


    /**
     * 获取html
     */
    @GetMapping("/html")
    public String getHtml() {
        return mailService.getHtml();
    }

}

